package com.woniu.commentorder.console;

import com.hc.entity.Agree;
import com.hc.entity.Paper;
import com.hc.entity.User;
import com.hc.utils.ResponseEntity;
import com.hc.vo.PaperVo;
import com.hc.vo.Videoutil;
import com.woniu.commentorder.service.Paperservice;
import com.woniu.commentorder.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("user")
public class Userconsole {
    @Autowired
    UserService userService;
    @Autowired
    Paperservice paperservice;

    @PostMapping("/getvideo")
    public ResponseEntity<List<Videoutil>> getByUserId(@RequestBody PaperVo paperVo) {
        int id = paperVo.getUserid();
        List<Videoutil> videoutils = new ArrayList<>();
//        User user = userService.getById(id);
        List<Agree> agrees = userService.getByUser(id);
          paperservice.seleByVo(paperVo).forEach(r -> {
            Videoutil videoutil = new Videoutil();
            videoutil.setId(r.getId() - 1);
//            videoutil.setIs_dianzan("false");
            agrees.forEach(c -> {
                if (c.getPaper().getId() == r.getId()) {
                    videoutil.setIs_dianzan("true");
                }
            });
            System.out.println(r.getUser().getId());
            videoutil.setProfile(userService.getById(r.getUser().getId()).getProfile());
            videoutil.setPreImg(r.getIaddress());
            videoutil.setSrc(r.getVaddress());
            videoutils.add(videoutil);
        });
        return new ResponseEntity<List<Videoutil>>(videoutils);
    }
//    @PostMapping("/loadvideo")
//    public ResponseEntity<List<Videoutil>> loadByUserId(@RequestBody User userid) {
//        int id = userid.getId();
//        List<Videoutil> videoutils = new ArrayList<>();
//        List<Agree> agrees = userService.getByUser(id);
//        paperservice.seleByCon(new Paper()).forEach(r -> {
//            Videoutil videoutil = new Videoutil();
//            videoutil.setId(r.getId() - 1);
////            videoutil.setIs_dianzan("false");
//            agrees.forEach(c -> {
//                if (c.getPaper().getId() == r.getId()) {
//                    videoutil.setIs_dianzan("true");
//                }
//            });
//            System.out.println(r.getUser().getId());
//            videoutil.setProfile(userService.getById(r.getUser().getId()).getProfile());
//            videoutil.setPreImg(r.getIaddress());
//            videoutil.setSrc(r.getVaddress());
//            videoutils.add(videoutil);
//        });
//        return new ResponseEntity<List<Videoutil>>(videoutils);
//    }
    @PostMapping("/dianzan")
    public ResponseEntity dianzan(@RequestBody Agree agree) {
        User user=new User();
        user.setId(1);
        agree.setUser(user);
        userService.dianzan(agree);
        return new ResponseEntity("点赞成功");
    }

    @PostMapping("/concel")
    public ResponseEntity concel(@RequestBody Agree agree) {
        User user=new User();
        user.setId(1);
        agree.setUser(user);
        userService.concel(agree);
        return new ResponseEntity("取消点赞");
    }
}
